package com.open.capacity.notice.validator;

import org.springframework.scheduling.support.CronExpression;

import com.open.capacity.notice.context.SendMessageJobContext;

import net.bytebuddy.matcher.ElementMatcher;

public class JobChecker implements ElementMatcher<SendMessageJobContext> {

	@Override
	public boolean matches(SendMessageJobContext contex) {
		if (!contex.getSendMessageJob().getTimer()) {
			if (!CronExpression.isValidExpression(contex.getSendMessageJob().getCron())) {
				contex.setMsg("无效的cron表达式");
				return false;
			}
		}
		return true;
	}

	// 匿名内部类，确保只有在第一次访问时才会被初始化
	private static class Holder {
		private static final JobChecker INSTANCE = new JobChecker();
	}

	public static JobChecker getInstance() {
		return Holder.INSTANCE;
	}

}
